package com.me.study.concurrent.thread;

/**
 * 变量的并发测试
 * 
 * @Title: com.me.concurrent.thread.T1
 * @author ME
 * @date 2019年1月14日 上午10:28:51
 */
public class TestA {
	public static void main(String[] args) {
		PrivateNumA p = new PrivateNumA();
		MyThreadA thread1 = new MyThreadA('A', p);
		MyThreadA thread2 = new MyThreadA('B', p);
		thread1.start();
		thread2.start();
	}

	public static class MyThreadA extends Thread {
		char i;
		PrivateNumA p;

		public MyThreadA(char i, PrivateNumA p) {
			this.i = i;
			this.p = p;
		}

		@Override
		public void run() {
			p.test(i);
		}
	}

	public static class PrivateNumA {
		public void test(char i) {
			int num = 0;
			try {
				if (i == 'A') {
					num = 100;

					System.out.println("线程A已经设置完毕");
					Thread.sleep(1000);
				} else {
					num = 200;
					System.out.println("线程B已经设置完毕");
				}
				System.out.println("线程" + i + "的值：" + num);

			} catch (InterruptedException e) {
				// TODO 自动生成的 catch 块
				e.printStackTrace();
			}
		}
	}
}
